﻿namespace DesignModeConsole.行为型.职责链模式.抽取试题;

/// <summary>
/// 抽屉责任链基类
/// </summary>
public abstract class ExtractExamAbstractHandler
{
    /// <summary>
    /// 下一个流程
    /// </summary>
    public ExtractExamAbstractHandler? NextHandler { get; set; }

    /// <summary>
    /// 抽象处理方法
    /// </summary>
    /// <param name="flowDto"></param>
    /// <returns></returns>
    public abstract Task<ExtractExamFlowDto> HandlerAsync(ExtractExamFlowDto flowDto);

    /// <summary>
    /// 执行下一个流程(满足条件就终止)
    /// </summary>
    /// <param name="flowDto"></param>
    /// <returns></returns>
    protected async Task<ExtractExamFlowDto> ExecuteNextHandler(ExtractExamFlowDto flowDto)
    {
        if (flowDto.ExtractCount == 0 || NextHandler is null)
            return flowDto;

        return await NextHandler.HandlerAsync(flowDto);
    }
}

/// <summary>
/// 中文试题抽取处理
/// </summary>
public class ChineseExamHandler : ExtractExamAbstractHandler
{
    public override async Task<ExtractExamFlowDto> HandlerAsync(ExtractExamFlowDto flowDto)
    {
        flowDto.ExamList.AddRange(new List<string> { "古诗", "成语" });
        return await ExecuteNextHandler(flowDto);
    }
}

/// <summary>
/// 数学试题抽取
/// </summary>
public class MathematicsExamHandler : ExtractExamAbstractHandler
{
    public override async Task<ExtractExamFlowDto> HandlerAsync(ExtractExamFlowDto flowDto)
    {
        flowDto.ExamList.AddRange(new List<string> { "一元二次方程式", "二元一次方程式" });
        return await ExecuteNextHandler(flowDto);
    }
}

/// <summary>
/// 英语试题抽取
/// </summary>
public class EnglishExamHandler : ExtractExamAbstractHandler
{
    public override async Task<ExtractExamFlowDto> HandlerAsync(ExtractExamFlowDto flowDto)
    {
        flowDto.ExamList.AddRange(new List<string> { "英语" });
        return await ExecuteNextHandler(flowDto);
    }
}